package top.jiangqiang.qyblog.common.base.query;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

@Data
@Schema(name = "翻页查询条件")
public class PageCondition implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    @Schema(description = "查询第几页的数据，默认第一页", defaultValue = "1")
    private Integer page = 1;
    @Schema(description = "每一页的数量，默认10条，传入-1则不分页", defaultValue = "10")
    private Integer size = 10;

    public <T> PageResult<T> toPage() {
        if (this.page == null) {
            this.page = 1;
        }
        if (this.size == null) {
            this.size = 10;
        }
        return new PageResult<>(this.page, this.size);
    }

    /**
     * @param tClass 指定类型
     * @return 指定泛型类型
     */
    @SuppressWarnings("unused")
    public <T> PageResult<T> toPage(Class<T> tClass) {
        return toPage();
    }
}
